package edu.mis.model;

import java.util.*;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.base.BaseOrderDetailCustomer;


@SuppressWarnings("serial")
public class OrderDetailCustomer extends BaseOrderDetailCustomer<OrderDetailCustomer> {


	public static final OrderDetailCustomer dao = new OrderDetailCustomer().dao();

    private Customer customer;
	private OrderList orderList;


	/**
	 * 表关联查询得到菜品的菜品号
	 * 类型：订单为1：N关系，得到菜品对象的类型
	 * @return
	 */
	public List<Record> findAllOrderDetailCustomersWithCustomer(String customerId){
		return Db.find("SELECT d.id,d.qty,c.customerName,c.price FROM(SELECT * FROM order_detail_customer  WHERE customerId=?) d LEFT JOIN customer c on d.customerId=c.id",customerId);
	}


	public List<Record> findAllRecord() {
		return Db.find("SELECT d.*,c.customerName,c.price FROM order_detail_customer d LEFT JOIN customer c ON d.customerId=c.id");
	}


	public List<OrderDetailCustomer> findAll(){
		return OrderDetailCustomer.dao.find("SELECT * FROM order_detail_customer");
	}
	public List<OrderDetailCustomer> findAllByOrderListId(Integer id) {
		return OrderDetailCustomer.dao.find("SELECT * FROM order_detail_customer WHERE orderListId=?",id);
	}


	public OrderList findOrderListByOrderListId() {
		return OrderList.dao.findById(get("orderListId"));
	}

	/**
	 * 表关联查询_得到订单详细的菜品
	 * 权限:用户为1:N关系，得到订单详细的菜品对象。
	 * @return
	 */
//	public Customer findCustomerByCustomerId(Integer customerId){
//		return Customer.dao.findById(customerId);
//	}
//
	public void setCustomer(Customer customer) {
		this.setCustomerId(customer.getId());
		this.customer = customer;

	}

	public Customer getCustomer() {
		return customer;
	}

	public OrderList getOrderList() {
		return orderList;
	}

	public void setOrderList(OrderList orderList) {
		this.setOrderListId(orderList.getId());
		this.orderList = orderList;
	}



}
